package com.dnjn.happiness.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.AppraiseXref;
import com.dnjn.happiness.biz.domain.vo.AppraiseXrefVO;
import com.dnjn.happiness.biz.service.IAppraiseXrefService;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * 维度评价Controller
 *
 * @author happiness
 * @date 2024-03-15
 */
@Tag(name = "biz appraiseXref 维度评价", description = "维度评价")
@RestController
@RequestMapping("/appraiseXref")
public class AppraiseXrefController extends BaseController {
    @Autowired
    private IAppraiseXrefService appraiseXrefService;

    /**
     * 查询维度评价列表
     */
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseXref:list')")
    @PostMapping("/list")
    @Log(title = "biz", businessType = BusinessType.LIST)
    public AjaxResult list(@RequestBody AppraiseXrefVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        AppraiseXref appraiseXref = new AppraiseXref();
        BeanUtils.copyPropsIgnoreNull(vo, appraiseXref);
        Page page = Page.of(current, size);
        Page<AppraiseXref> list = appraiseXrefService.page(page, Wrappers.query(appraiseXref));
        return success(list);
    }

    /**
     * 获取维度评价详细信息
     */
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseXref:query')")
    @GetMapping(value = "/{appraise_xref_id}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable("appraise_xref_id") Long appraise_xref_id) {
        return success(appraiseXrefService.getById(appraise_xref_id));
    }

    /**
     * 新增维度评价
     */
    @Log(title = "维度评价", businessType = BusinessType.INSERT)
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseXref:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AppraiseXrefVO vo) {
        AppraiseXref appraiseXref = new AppraiseXref();
        BeanUtils.copyPropsIgnoreNull(vo, appraiseXref);

        appraiseXref.setCreateBy(SecurityUtils.getUsername());
        return toAjax(appraiseXrefService.save(appraiseXref));
    }

    /**
     * 修改维度评价
     */
    @Log(title = "维度评价", businessType = BusinessType.UPDATE)
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseXref:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody AppraiseXrefVO vo) {
        AppraiseXref appraiseXref = new AppraiseXref();
        BeanUtils.copyPropsIgnoreNull(vo, appraiseXref);
        return toAjax(appraiseXrefService.updateById(appraiseXref));
    }

    /**
     * 删除维度评价
     */
    @Log(title = "维度评价", businessType = BusinessType.DELETE)
    //@RequiresPermissions("@ss.hasPermi('biz:appraiseXref:remove')")
    @DeleteMapping("/{appraise_xref_ids}")
    public AjaxResult remove(@PathVariable Long[] appraise_xref_ids) {
        return toAjax(appraiseXrefService.removeBatchByIds(Arrays.asList(appraise_xref_ids)));
    }
}
